﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>首页</title>
<script type="text/javascript">
    var path = window.document.location.href;
	var pathName = window.document.location.pathname;
	var hostPath = path.substring(0, path.indexOf(pathName));
	var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
	document.write('<scr' + 'ipt src="' + projectName + '/js/jquery-easyui/jquery.min.js"></scr'+'ipt>');
	document.write('<scr' + 'ipt src="' + projectName + '/js/jquery/jquery-migrate-1.2.1.js"></scr'+'ipt>');
	document.write('<scr' + 'ipt src="' + projectName + '/js/ztree/jquery.ztree.core-3.5.js"></scr'+'ipt>');
	document.write('<link rel="stylesheet" type="text/css" href="' + projectName + '/css/basic/main_css.css">');
	document.write('<link rel="stylesheet" type="text/css" href="' + projectName + '/css/ztree/zTreeMenuStyle.css">');
</script>
<style type="text/css">
#shadediv{display:none;position:absolute;
			top:0%;left:0%;
			width:100%;height:100%;
			z-index:1001;-moz-opacity:0.1;
			opacity:10;filter:Alpha(opacity=10);}
</style>
<script type="text/javascript">
		var userId="userId";

		function showshadediv(){
			document.getElementById("shadediv").style.display="block";
		}
		function hideshadediv(){
			document.getElementById("shadediv").style.display="none";
		}

		/**退出系统**/
		function logout(){
			if(confirm("您确定要退出本系统吗？")){
				$.ajax({
				    type: "POST",
				    url: projectName+"/logout",
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
				    dataType: "json",
				    success: function(data){
				    	window.location.href = projectName;
				    },
					error:function(err, status){
						window.location.href = projectName;
					}
				});
			}
		}

		/**获得公共数据**/
		function  getSysData(){
			var time = new Date();
			var hh = time.getHours();
			var mm = time.getMinutes();

			$('#top_op li').each(function(index,domEle){
				if(  0==index ){
					$(this).find('img').attr('src', projectName+'/images/common/user.jpg');
				}else if( 1==index ){
					$(this).find('img').attr('src', projectName+'/images/common/month.jpg');
				}else if(  2==index ){
					$(this).find('img').attr('src', projectName+'/images/common/date.jpg');
				}

			});

			$('#TabPage2 li').each(function(index,domEle){
				if(  0==index ){
					$(this).find('img').attr('src', projectName+'/images/common/1_hover.jpg');
				}else if( 1==index ){
					$(this).find('img').attr('src', projectName+'/images/common/2.jpg');
				}else if(  2==index ){
					$(this).find('img').attr('src', projectName+'/images/common/3.jpg');
				}

			});

			$('#nav_show_img').attr('src', projectName+'/images/common/nav_hide.png');
			$('#nav_module_img').attr('src', projectName+'/images/common/module_1.png');
			$('#top_logo_img').attr('src', projectName+'/images/common/logo.jpg');
			$('#top_close_img').attr('src', projectName+'/images/common/close.jpg');

		}

		/* zTree插件加载目录的处理  */
		var zTree;
		var setting = {
				view: {
					dblClickExpand: false,
					showLine: false,
					expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
				},
				data: {
					key: {
						name: "resourceName"
					},
					simpleData: {
						enable:true,
						idKey: "id",
						pIdKey: "parentId",
						rootPId: ""
					}
				},
				callback: {
					onClick: zTreeOnClick
				}
		};

		var curExpandNode = null;
		function beforeExpand(treeId, treeNode) {
			var pNode = curExpandNode ? curExpandNode.getParentNode():null;
			var treeNodeP = treeNode.parentTId ? treeNode.getParentNode():null;
			for(var i=0, l=!treeNodeP ? 0:treeNodeP.children.length; i<l; i++ ) {
				if (treeNode !== treeNodeP.children[i]) {
					zTree.expandNode(treeNodeP.children[i], false);
				}
			}
			while (pNode) {
				if (pNode === treeNode) {
					break;
				}
				pNode = pNode.getParentNode();
			}
			if (!pNode) {
				singlePath(treeNode);
			}

		}
		function singlePath(newNode) {
			if (newNode === curExpandNode){
				return;
			}
			if (curExpandNode && curExpandNode.open==true) {
				if (newNode.parentTId === curExpandNode.parentTId) {
					zTree.expandNode(curExpandNode, false);
				} else {
					var newParents = [];
					while (newNode) {
						newNode = newNode.getParentNode();
						if (newNode === curExpandNode) {
							newParents = null;
							break;
						} else if (newNode) {
							newParents.push(newNode);
						}
					}
					if (newParents!=null) {
						var oldNode = curExpandNode;
						var oldParents = [];
						while (oldNode) {
							oldNode = oldNode.getParentNode();
							if (oldNode) {
								oldParents.push(oldNode);
							}
						}
						if (newParents.length>0) {
							for (var i = Math.min(newParents.length, oldParents.length)-1; i>=0; i--) {
								if (newParents[i] !== oldParents[i]) {
									zTree.expandNode(oldParents[i], false);
									break;
								}
							}
						}else {
							zTree.expandNode(oldParents[oldParents.length-1], false);
						}
					}
				}
			}
			curExpandNode = newNode;
		}

		function onExpand(event, treeId, treeNode) {
			curExpandNode = treeNode;
		}

		/** 用于捕获节点被点击的事件回调函数  **/
		function zTreeOnClick(event, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("dleft_tab1");
			zTree.expandNode(treeNode, null, null, null, true);
			// 规定：如果是父类节点，不允许单击操作
			if(treeNode.isParent){
				return false;
			}
			// 如果节点路径为空或者为"#"，不允许单击操作
			if(null==treeNode.accessPath || treeNode.accessPath=="" || treeNode.accessPath=="#"){
				alert("没有可访问的资源!");
				return false;
			}

            var authCodeKey = '?authCode=';
            if(treeNode.accessPath.indexOf("?")>-1){
                authCodeKey = '&authCode=';
            }

		    // 跳到该节点下对应的路径
		    $('#rightMain').attr('src', projectName+"/"+treeNode.accessPath+authCodeKey+treeNode.authCode);

		    if( treeNode.isParent ){
			    $('#here_area').html('当前位置：<a onclick="goIndex(); return false;" style="color:#1A5CC6">主页</a>'+treeNode.getParentNode().resourceName+'&nbsp;>&nbsp;<span style="color:#1A5CC6">'+treeNode.resourceName+'</span>');
		    }else{
			    $('#here_area').html('当前位置：<a onclick="goIndex(); return false;" style="color:#1A5CC6">主页</a>&nbsp;>&nbsp;<span>'+treeNode.resourceName+'</span>');
		    }
		};

		/* 上方菜单 */
		function switchTab(tabpage,tabid){
			var oItem = document.getElementById(tabpage).getElementsByTagName("li");
		    for(var i=0; i<oItem.length; i++){
		        var x = oItem[i];
		        x.className = "";
			}
			if('left_tab1' == tabid){
				$(document).ajaxStart(onStart).ajaxSuccess(onStop);
			  	loadMenu('YWMK', 'dleft_tab1');
			}else  if('left_tab2' == tabid){
				$(document).ajaxStart(onStart).ajaxSuccess(onStop);
				loadMenu('XTGL', 'dleft_tab1');
			}else  if('left_tab3' == tabid){
				$(document).ajaxStart(onStart).ajaxSuccess(onStop);
				loadMenu('QITA', 'dleft_tab1');
			}
		}

		function loadMenu(resourceType, treeObj){
			showshadediv();
			$.ajax({
				type : "POST",
				dataType : "json",
				contentType : "application/json;charset=utf-8",
				url:projectName + "/resource/query",
				crossDomain:true,
				xhrFields:{
					withCredentials:true
				},
				data:JSON.stringify({
					"resourceType":resourceType,
				}),
				success:function(data){
					if(!data.success){
				    	alert(data.message);
				    	return;
				    }
		            // 如果返回数据不为空，加载"业务模块"目录
		            data = data.rows;
		            if(data != null){
		                // 将返回的数据赋给zTree
		                $.fn.zTree.init($("#"+treeObj), setting, data);
		                zTree = $.fn.zTree.getZTreeObj(treeObj);
		                if( zTree ){
		                    // 默认展开所有节点
		                    zTree.expandAll(false);
		                    hideshadediv();
		                }
		            }
				},
				error:function(err, status){
					alert("系统错误:"+err.responseText);
				}
			});
		}

		function onStart(){
			$("#ajaxDialog").show();
		}
		function onStop(){
			$("#ajaxDialog").hide();
		}

		function goIndex(){
			 // 跳到该节点下对应的路径
		    $('#rightMain').attr('src', projectName+"/html/introduce.html");
		}

		/**隐藏或者显示侧边栏**/
		function switchSysBar(flag){
			var side = $('#side');
	        var left_menu_cnt = $('#left_menu_cnt');
			if( flag==true ){
				left_menu_cnt.show(100, 'linear');
				side.css({width:'280px'});
				$('#top_nav').css({width:'77%', left:'304px'});
	        	$('#main').css({left:'280px'});
			}else{
		        if ( left_menu_cnt.is(":visible") ) {
					left_menu_cnt.hide(100, 'linear');
					side.css({width:'60px'});
		        	$('#top_nav').css({width:'100%', left:'60px', 'padding-left':'28px'});
		        	$('#main').css({left:'60px'});
		        	$("#show_hide_btn").find('img').attr('src', projectName+'/images/common/nav_show.png');
		        } else {
					left_menu_cnt.show(100, 'linear');
					side.css({width:'280px'});
					$('#top_nav').css({width:'77%', left:'304px', 'padding-left':'0px'});
		        	$('#main').css({left:'280px'});
		        	$("#show_hide_btn").find('img').attr('src', projectName+'/images/common/nav_hide.png');
		        }
			}
		}
	</script>
</head>
<body>
	<div id="shadediv"></div>
    <div id="top">
		<div id="top_logo">
			<img id="top_logo_img" alt="logo" src="" width="274" height="49" style="vertical-align:middle;">
		</div>
		<div id="top_links" >
			<div id="top_op" >
				<ul>
					<li>
						<img alt="当前用户" src="">：
						<span id="curr_user">user</span>
					</li>
					<li>
						<img alt="当前机构" src="">：
						<span id="curr_orgn">orgn</span>
					</li>
					<li>
						<img alt="日期" src="">：
						<span id="curr_date"></span>
					</li>
				</ul>
			</div>
			<div id="top_close">
				<a href="javascript:void(0);" onclick="logout();" target="_parent">
					<img id="top_close_img" alt="退出系统" title="退出系统" src="" style="position: relative; top: 10px; left: 25px;">
				</a>
			</div>
		</div>
	</div>
    <!-- side menu start -->
	<div id="side">
		<div id="left_menu">
		 	<ul id="TabPage2" style="height:200px; margin-top:50px;">
				<li id="left_tab1" class="selected" onClick="javascript:switchTab('TabPage2','left_tab1');" title="业务模块">
					<img alt="业务模块" title="业务模块" src="" width="33" height="31">
				</li>
				<li id="left_tab2" onClick="javascript:switchTab('TabPage2','left_tab2');" title="系统管理">
					<img alt="系统管理" title="系统管理" src="" 	  width="33" height="31">
				</li>
				<li id="left_tab3" onClick="javascript:switchTab('TabPage2','left_tab3');" title="其    他">
					<img alt="其    他" title="其    他" src="" 	  width="33" height="31">
				</li>
			</ul>
			<div id="nav_show" style="position:absolute; bottom:0px; padding:10px;">
				<a href="javascript:;" id="show_hide_btn">
					<img id="nav_show_img" alt="显示/隐藏" title="显示/隐藏" src="" width="35" height="35">
				</a>
			</div>
		 </div>
		 <div id="left_menu_cnt">
		 	<div id="nav_module">
		 		<img id="nav_module_img" src="" width="210" height="58"/>
		 	</div>
		 	<div id="nav_resource">
		 		<ul id="dleft_tab1" class="ztree"></ul>
		 	</div>
		 </div>
	</div>
    <!-- side menu start -->
    <div id="top_nav">
	 	<span id="here_area">当前位置：<a onclick="goIndex(); return false;" style="color:#1A5CC6">主页</a>&nbsp;&gt;&nbsp;主页</span>
	</div>
    <div id="main">
      	<iframe name="right" id="rightMain" src="" frameborder="0" scrolling="auto" width="100%" height="100%" ></iframe>
    </div>
</body>
</html>
<script type="text/javascript">
	$.ajax({
	    type: "POST",
	    url: projectName+"/system/userinfo/current",
		crossDomain:true,
		xhrFields:{
			withCredentials:true
		},
	    dataType: "json",
	    success: function(data){
	    	var loginUser = data.entity;
	    	var txnDate = loginUser.busiDate;
	    	userId = loginUser.userId;
	    	document.getElementById("curr_date").innerHTML =  txnDate.substr(0,4)+"-"+txnDate.substr(4,2)+"-"+txnDate.substr(6,2);
			document.getElementById("curr_user").innerHTML =  loginUser.userName;
			document.getElementById("curr_orgn").innerHTML =  loginUser.orgnName;
			$(document).attr("title",loginUser.sysName);
	    	$('iframe').attr('src',projectName+'/html/introduce.html');
	    }
	});

	getSysData();

	$(document).ajaxStart(onStart).ajaxSuccess(onStop);
	loadMenu('YWMK', "dleft_tab1");
	if( zTree ){
		zTree.expandAll(true);// 默认展开所有节点
	}

	$('#TabPage2 li').click(function(){
		var index = $(this).index();
		$(this).find('img').attr('src', projectName+'/images/common/'+ (index+1) +'_hover.jpg');
		$(this).css({background:'#fff'});
		$('#nav_module').find('img').attr('src', projectName+'/images/common/module_'+ (index+1) +'.png');
		$('#TabPage2 li').each(function(i, ele){
			if( i!=index ){
				$(ele).find('img').attr('src', projectName+'/images/common/'+ (i+1) +'.jpg');
				$(ele).css({background:'#044599'});
			}
		});
		// 显示侧边栏
		switchSysBar(true);
	});

	// 显示隐藏侧边栏
	$("#show_hide_btn").click(function() {
        switchSysBar();
    });
</script>